In Review

In this tutorial, you have learned the following:

Further Study

Even with a simple tutorial like this, there are many things to play around with and investigate.

  • Change the color value set by the fragment shader to different values. Use values in the range [0, 1], and then see what happens when you go outside that range.

  • Change the positions of the vertex data. Keep position values in the [-1, 1] range, then see what happens when triangles go outside this range. Notice what happens when you change the Z value of the positions (note: nothing should happen while they're within the range). Keep W at 1.0 for now.

  • Change the values that reshape gives to glViewport. Make them bigger or smaller than the window and see what happens. Shift them around to different quadrants within the window.

  • Change the reshape function so that it respects aspect ratio. This means that the area rendered to may be smaller than the window area. Also, try to make it so that it always centers the area within the window.

  • Change the clear color, using values in the range [0, 1]. Notice how this interacts with changes to the viewport above.

  • Add another 3 vertices to the list, and change the number of vertices sent in the glDrawArrays call from 3 to 6. Add more and play with them.

OpenGL Functions of Note

glClearColor, glClear

These functions clear the current viewable area of the screen. glClearColor sets the color to clear, while glClear with the GL_COLOR_BUFFER_BIT value causes the image to be cleared with that color.

glGenBuffers, glBindBuffer, glBufferData

These functions are used to create and manipulate buffer objects. glGenBuffers creates one or more buffers, glBindBuffer attaches it to a location in the context, and glBufferData allocates memory and fills this memory with data from the user into the buffer object.

glEnableVertexAttribArray, glDisableVertexAttribArray, glVertexAttribPointer

These functions control vertex attribute arrays. glEnableVertexAttribArray activates the given attribute index, glDisableVertexAttribArray deactivates the given attribute index, and glVertexAttribPointer defines the format and source location (buffer object) of the vertex data.

glDrawArrays

This function initiates rendering, using the currently active vertex attributes and the current program object (among other state). It causes a number of vertices to be pulled from the attribute arrays in order.

glViewport

This function defines the current viewport transform. It defines as a region of the window, specified by the bottom-left position and a width/height.

glCreateShader, glShaderSource, glCompileShader, glDeleteShader

These functions create a working shader object. glCreateShader simply creates an empty shader object of a particular shader stage. glShaderSource sets strings into that object; multiple calls to this function simply overwrite the previously set strings. glCompileShader causes the shader object to be compiled with the previously set strings. glDeleteShader causes the shader object to be deleted.

glCreateProgram, glAttachShader, glLinkProgram, glDetachShader

These functions create a working program object. glCreateProgram creates an empty program object. glAttachShader attaches a shader object to that program. Multiple calls attach multiple shader objects. glLinkProgram links all of the previously attached shaders into a complete program. glDetachShader is used to remove a shader object from the program object; this does not affect the behavior of the program.

glUseProgram

This function causes the given program to become the current program. All rendering taking place after this call will use this program for the various shader stages. If the program 0 is given, then no program is current.

glGetAttribLocation

This function retrieves the attribute index of a named attribute. It takes the program to find the attribute in, and the name of the input variable of the vertex shader that the user is looking for the attribute index to.